//
//  YPInvestDetailViewController.m
//  ChengHuiTong
//
//  Created by KiVen on 15/11/3.
//  Copyright © 2015年 张文权. All rights reserved.
//

#import "YPInvestDetailViewController.h"
#import "YPInvestDetailSectionOneView.h"
#import "YPInvestDetailSectionTwoView.h"
#import "DQAlertView.h"
#import "OptionModel.h"
#import "SetPassWordViewController.h"
#import "YPTenderViewController.h"
#import "YRChildVC.h"
#import "YRControlViewController.h"

@interface YPInvestDetailViewController ()<UIScrollViewDelegate,DQAlertViewDelegate,UITextFieldDelegate,UIWebViewDelegate,UITextFieldDelegate>{
    
    UIScrollView *_backGroundScrollView;
//    自定义的alertview
    DQAlertView * _customAlertView;
    
    NSMutableArray * _optionArray;
//    立即投资
    UIButton * _investmentStateButton;
    
    //    计划投入 输入框
    UITextField *_plansInvestTextField;
//    预计收益的内容
    UILabel *_expectedEarningsNumberLabel;
//    投资奖励的内容
    UILabel *_investAwardContentLabel;

     UILabel *_titleLabel;
    
    
    NSDictionary*_dataDic;

    NSMutableArray *vcArr;
    
    NSMutableArray *webArr;

    BOOL isGET;
    
    YRControlViewController *controlVC;
    
    BOOL _hasCancledRequest;

}

@end

@implementation YPInvestDetailViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    vcArr = [@[] mutableCopy];
    
    webArr= [@[] mutableCopy];
    
    self.navigationItem.title = @"标的详情";
    
    isGET=NO;

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(backTop) name:@"backTop" object:nil];
    
    _optionArray = [[NSMutableArray alloc]initWithCapacity:0];
    
    [self requestInvestDetailViewData];

    
}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    NSLog(@"详情出现");
    [MobClick beginLogPageView:@"投资详情"];
    if (_hasCancledRequest && self.investDetailModel.operation.integerValue != 6 &&[self.investDetailModel.surplus_time doubleValue]>=[[NSDate date] timeIntervalSince1970] ) {
        [self timerFire];
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    [MobClick endLogPageView:@"投资详情"];
    [[self class] cancelPreviousPerformRequestsWithTarget:self];
    _hasCancledRequest = YES;
}

#pragma mark - 系统委托方法(UITableViewDelegate)


#pragma mark - textField

- (void) showtextFiledContents{
    
    if (_plansInvestTextField.text.length>0) {
        
        _expectedEarningsNumberLabel.textColor = UIColorFromRGB(0xdb3939);
        _investAwardContentLabel.textColor = UIColorFromRGB(0xdb3939);

    }else{
        
        _expectedEarningsNumberLabel.textColor = UIColorFromRGB(0x8c8c8c);
        _investAwardContentLabel.textColor = UIColorFromRGB(0x8c8c8c);

    }
    
    //        输入的金额
    double enterAmount = [_plansInvestTextField.text doubleValue];
    
    //奖励金额
    _investAwardContentLabel.text = [NSString stringWithFormat:@"%.2f",enterAmount*[self.investDetailModel.award doubleValue]/100];
    //总收益
    _expectedEarningsNumberLabel.text = [AppTools getFinalProfitWithEnterAmount:enterAmount
                                                                            apr:self.investDetailModel.apr
                                                                      timeLimit:self.investDetailModel.time_limit
                                                                          style:self.investDetailModel.style
                                                                    is_datetype:self.investDetailModel.is_datetype];

}

- (NSString *) decimalwithFormat:(NSString *)format  floatV:(float)floatV
{
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    
    [numberFormatter setPositiveFormat:format];
    
    return  [numberFormatter stringFromNumber:[NSNumber numberWithFloat:floatV]];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;  {
    
    
    if (textField == _plansInvestTextField) {
        if (string.length == 0) return YES;
        
        NSInteger existedLength = textField.text.length;
        NSInteger selectedLength = range.length;
        NSInteger replaceLength = string.length;
        if (existedLength - selectedLength + replaceLength > 10) {
            return NO;
        }
    }
    
    
    return YES;
}

- (void)textFieldDidChange:(UITextField *)textField
{
    if (textField == _plansInvestTextField) {
        if (textField.text.length > 10) {
            textField.text = [textField.text substringToIndex:10];
        }
    }

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    
    return YES;
}

#pragma mark - scrollerview
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;{
    NSLog(@"将开始降速时scrollViewWillBeginDecelerating");
    
    if (scrollView == _backGroundScrollView) {
        
        
        
        float y = scrollView.contentOffset.y;
        
        if (y <= 0) {
            
            NSLog(@"上拉刷新");
        }
        else if (y < 50 && y > 0){
            
            [scrollView setContentOffset:CGPointMake(0, scrollView.contentSize.height-scrollView.frame.size.height) animated:YES];
            NSLog(@"上弹？？？？？");
        }
        else{
            //            _backGroundScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, _daPagesContainer.view.frame.origin.y +SCREEN_HEIGHT-64-44-60);
            
            _backGroundScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, controlVC.view.frame.origin.y +SCREEN_HEIGHT-64-44-60);
            [_backGroundScrollView setContentOffset:CGPointMake(0, controlVC.view.frame.origin.y) animated:YES];
            _backGroundScrollView.scrollEnabled = NO;
            
            for (YRChildVC * childVC in vcArr) {
                childVC.web.scrollView.scrollEnabled = YES;
                childVC.auditScrollView.scrollEnabled = YES;
            }
            
            
            
        }
        
        
    }
    
    
    
}

#pragma mark - 自定义委托方法(CustomDelegate)

#pragma mark - 事件响应

//立即投标
- (void)investmentStateButtonClick{
    
    if ([YPShareAccountInfo shareAccountInfo].token == nil) {
        
        YPLogonViewController * logonVC = [[YPLogonViewController alloc]init];
        
        BaseNavigationController * nav = [[BaseNavigationController alloc]initWithRootViewController:logonVC];
        
        [self.navigationController presentViewController:nav animated:YES completion:^{
        }];
 
    }
    else{

        YPTenderViewController *tenderVC = [[YPTenderViewController alloc]init];
        tenderVC.investDetailModel = self.investDetailModel;
        [self.navigationController pushViewController:tenderVC animated:YES];
    }
    
    
    
}

//计算器
- (void)calculatorButtonClick{
    
    
    if ([self.investDetailModel.award floatValue]>0) {
        
        [self showcalculatorViewAndAward];
        
    }else{
    
        [self showcalculatorView];
        
        
    }

    

    
}

//有奖励
-(void)showcalculatorViewAndAward{
    
    _customAlertView = [[DQAlertView alloc] initWithTitle:nil message:nil cancelButtonTitle:nil otherButtonTitle:nil];
    _customAlertView.customFrame = CGRectMake(30, 80, SCREEN_WIDTH-(2*30), 160);
    
    if (SCREEN_WIDTH==480) {
        
        _customAlertView.top=80;
        
    }else{
        
        _customAlertView.top=130;
        
    }
    
    
    _customAlertView.shouldDismissOnOutsideTapped = YES;
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-(2*30), 160)];
    contentView.backgroundColor = [UIColor whiteColor];
    
    
    
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-(2*30), 30)];
    titleLabel.text = @"收益计算器";
    titleLabel.textColor = kColor_AppNavColor;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:titleLabel];
    
    UILabel * lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 39.5f, SCREEN_WIDTH-(2*30), .5)];
    lineLabel.backgroundColor = UIColorFromRGB(0xE2E2E2);
    [contentView addSubview:lineLabel];
    
    
    
    
    //    计划投入
    UILabel * plansInvestLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(lineLabel.frame)+10, 70, 30)];
    plansInvestLabel.text = @"计划投入";
    //    plansInvestLabel.backgroundColor = [UIColor cyanColor];
    [contentView addSubview:plansInvestLabel];
    //    计划投入 输入框
    
    UILabel * boderLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(plansInvestLabel.frame)+5, lineLabel.bottom+5, SCREEN_WIDTH-(2*30)-20-20-70-5-5-30, 30)];
    
    boderLabel.layer.cornerRadius =2.5;
    boderLabel.clipsToBounds =YES;
    boderLabel.layer.borderColor = kColor_greyAshTitleColor.CGColor;
    boderLabel.layer.borderWidth=1;
    boderLabel.userInteractionEnabled =YES;
    [contentView addSubview:boderLabel];
    
    
    
    _plansInvestTextField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-(2*30)-20-20-70-5-5-5-30, 35)];
    
    
    _plansInvestTextField.font=[UIFont systemFontOfSize:14];
    //    _plansInvestTextField.backgroundColor = [UIColor orangeColor];
    _plansInvestTextField.borderStyle =UITextBorderStyleNone;
    //    _plansInvestTextField.placeholder = @"输入金额";
    _plansInvestTextField.delegate = self;
    _plansInvestTextField.textColor = UIColorFromRGB(0x8c8c8c);
    [_plansInvestTextField becomeFirstResponder];
    _plansInvestTextField.textAlignment = NSTextAlignmentRight;
    [_plansInvestTextField addTarget:self action:@selector(showtextFiledContents) forControlEvents:UIControlEventEditingChanged];
    //    带小数点的键盘
    //UIKeyboardTypeDecimalPad
    _plansInvestTextField.keyboardType = UIKeyboardTypeDecimalPad;
    [boderLabel addSubview:_plansInvestTextField];
    
    
    for (int i = 0; i < 3; i++) {
        //    元
        UILabel * rmbLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(boderLabel.frame)+5,plansInvestLabel.top+(5+30)*i, 30, 30)];
        rmbLabel.text = @"元";
        [contentView addSubview:rmbLabel];
        
    }
    
    
    //    预计收益
    UILabel * expectedEarningsLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(plansInvestLabel.frame)+5, 70, 30)];
    expectedEarningsLabel.text = @"预计收益";
    [contentView addSubview:expectedEarningsLabel];
    //    预计收益数字
    _expectedEarningsNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(expectedEarningsLabel.frame)+5, CGRectGetMaxY(plansInvestLabel.frame)+5, SCREEN_WIDTH-(2*30)-20-20-70-5-5-30, 30)];
    //    _expectedEarningsNumberLabel.backgroundColor = [UIColor orangeColor];
    _expectedEarningsNumberLabel.text = @"0.00";
    _expectedEarningsNumberLabel.textColor = UIColorFromRGB(0x8c8c8c);
    
    
    _expectedEarningsNumberLabel.font=[UIFont systemFontOfSize:14];
    
    _expectedEarningsNumberLabel.textAlignment = NSTextAlignmentRight;
    [contentView addSubview:_expectedEarningsNumberLabel];
    
    
    //投资奖励
    
    UILabel * investAwardLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, expectedEarningsLabel.bottom+5, 70, 30)];
    
    //    investAwardLabel.backgroundColor = [UIColor orangeColor];
    
    investAwardLabel.text = @"投资奖励";
    
    [contentView addSubview:investAwardLabel];
    
    _investAwardContentLabel = [[UILabel alloc]initWithFrame:CGRectMake(investAwardLabel.right+5, _expectedEarningsNumberLabel.bottom+5, SCREEN_WIDTH-(2*30)-20-20-70-5-5-30, 30)];
    
    //    _investAwardContentLabel.backgroundColor = [UIColor orangeColor];
    
    _investAwardContentLabel.text = @"0.00";
    
    _investAwardContentLabel.textColor = UIColorFromRGB(0x8c8c8c);
    
    _investAwardContentLabel.textAlignment = NSTextAlignmentRight;
    
     _investAwardContentLabel.font=[UIFont systemFontOfSize:14];
    
    [contentView addSubview:_investAwardContentLabel];
    
    
    
    
    
    _customAlertView.contentView = contentView;
    
    [_customAlertView show];
}

//无奖励
-(void)showcalculatorView{
    
    
    
    _customAlertView = [[DQAlertView alloc] initWithTitle:nil message:nil cancelButtonTitle:nil otherButtonTitle:nil];
    
    
    _customAlertView.customFrame = CGRectMake(30, 80, SCREEN_WIDTH-(2*30), 130);
    
    if (SCREEN_WIDTH==480) {
        
        _customAlertView.top=80;
        
    }else{
        
        _customAlertView.top=130;
        
    }
    
    _customAlertView.shouldDismissOnOutsideTapped = YES;
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-(2*30), 130)];
    contentView.backgroundColor = [UIColor whiteColor];
    
    
    
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-(2*30), 30)];
    titleLabel.text = @"收益计算器";
    titleLabel.textColor = kColor_AppNavColor;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:titleLabel];
    
    UILabel * lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 39.5f, SCREEN_WIDTH-(2*30), .5)];
    lineLabel.backgroundColor = UIColorFromRGB(0xE2E2E2);
    [contentView addSubview:lineLabel];
    
    
    
    
    //    计划投入
    UILabel * plansInvestLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(lineLabel.frame)+10, 70, 30)];
    plansInvestLabel.text = @"计划投入";
    //    plansInvestLabel.backgroundColor = [UIColor cyanColor];
    [contentView addSubview:plansInvestLabel];
    //    计划投入 输入框
    
    UILabel * boderLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(plansInvestLabel.frame)+5, lineLabel.bottom+5, SCREEN_WIDTH-(2*30)-20-20-70-5-5-30, 30)];
    
    boderLabel.layer.cornerRadius =2.5;
    boderLabel.clipsToBounds =YES;
    boderLabel.layer.borderColor = kColor_greyAshTitleColor.CGColor;
    boderLabel.layer.borderWidth=1;
    boderLabel.userInteractionEnabled =YES;
    [contentView addSubview:boderLabel];
    
    
    
    _plansInvestTextField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-(2*30)-20-20-70-5-5-5-30, 35)];
    //    _plansInvestTextField.backgroundColor = [UIColor orangeColor];
    _plansInvestTextField.borderStyle =UITextBorderStyleNone;
    
    _plansInvestTextField.font=[UIFont systemFontOfSize:14];
    
    //    _plansInvestTextField.placeholder = @"输入金额";
    _plansInvestTextField.delegate = self;
    _plansInvestTextField.textColor = UIColorFromRGB(0x8c8c8c);
    [_plansInvestTextField becomeFirstResponder];
    _plansInvestTextField.textAlignment = NSTextAlignmentRight;
    [_plansInvestTextField addTarget:self action:@selector(showtextFiledContents) forControlEvents:UIControlEventEditingChanged];
    //    带小数点的键盘
    //UIKeyboardTypeDecimalPad
    _plansInvestTextField.keyboardType = UIKeyboardTypeDecimalPad;
    [boderLabel addSubview:_plansInvestTextField];
    
    
    for (int i = 0; i < 2; i++) {
        //    元
        UILabel * rmbLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(boderLabel.frame)+5,plansInvestLabel.top+(5+30)*i, 30, 30)];
        rmbLabel.text = @"元";
        [contentView addSubview:rmbLabel];
        
    }
    
    
    //    预计收益
    UILabel * expectedEarningsLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(plansInvestLabel.frame)+5, 70, 30)];
    expectedEarningsLabel.text = @"预计收益";
    [contentView addSubview:expectedEarningsLabel];
    //    预计收益数字
    _expectedEarningsNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(expectedEarningsLabel.frame)+5, CGRectGetMaxY(plansInvestLabel.frame)+5, SCREEN_WIDTH-(2*30)-20-20-70-5-5-30, 30)];
    //    _expectedEarningsNumberLabel.backgroundColor = [UIColor orangeColor];
    _expectedEarningsNumberLabel.text = @"0.00";
    _expectedEarningsNumberLabel.textColor = UIColorFromRGB(0x8c8c8c);
     _expectedEarningsNumberLabel.font=[UIFont systemFontOfSize:14];
    
    _expectedEarningsNumberLabel.textAlignment = NSTextAlignmentRight;
    [contentView addSubview:_expectedEarningsNumberLabel];
    
    //    投资奖励
    
    
    
    
    
    _customAlertView.contentView = contentView;
    
    [_customAlertView show];
    
    
    
}
#pragma mark -私有
- (void)configInvestStateBtn{
    
    NSString *(^ getInvestStateBlock)(NSInteger) = ^(NSInteger operation){
        
        NSString *states = @"";
        switch (operation) {
            case 2:
                states = @"立即投标";
                break;
            case 3:
                states = @"满标复审中";
                break;
            case 5:
                states = @"流标";
                break;
            case 6:
                states = @"还款中";
                break;
            case 7:
                states = @"已完成";
                break;
            case 8:
                states = @"继续投标";
                break;
                
            default:
                break;
        }
        return states;
    };
    
    NSInteger operation = [self.investDetailModel.operation integerValue];
    [_investmentStateButton setTitle:getInvestStateBlock(operation) forState:UIControlStateNormal];
    
    if (operation != 2 && operation != 8) {
        _investmentStateButton.userInteractionEnabled = NO;
        _investmentStateButton.backgroundColor = UIColorFromRGB(0xb5b5b5);
    }

}
- (void)requestInvestDetailViewData{
    
    YPInvestmentDetailsBin * bin = [[YPInvestmentDetailsBin alloc]init];

    if ([YPShareAccountInfo shareAccountInfo].token == nil) {
        
        bin.bid = self.investModel.bid;

    }else{
        
        bin.token = [YPShareAccountInfo shareAccountInfo].token;
        bin.bid = self.investModel.bid;
 
    }
    
    
    
    [YPHttpRequestMethod sendAsyRequestURL:CMD_INVESTMENT_DETAILS withData:[bin dictionaryValue] withCompletionBlock:^(NSDictionary *responseDictionary) {
        NSLog(@"responseDictionary==%@",responseDictionary);
        
        isGET=YES;
        
        if ([responseDictionary[@"status"] intValue] == 0) {
            
            YPInvestDetailModel * model = [[YPInvestDetailModel alloc] initWithDictionary:responseDictionary];
            self.investDetailModel = model;
            
            _dataDic=responseDictionary[@"verify"];
            
        }
        
        if (!_backGroundScrollView) {
            
            [self creatInvestDetailView];
            
        }else{
            
            [self configInvestStateBtn];
        }
        
        
        [self.sectionA receiveInvestDetailModel:self.investDetailModel];
        
        [self.sectionB receiveDetailModel:self.investDetailModel];

        if (self.investDetailModel.review_time_local.length > 0 && self.investDetailModel.review_time_local.doubleValue > 0) {
            
            self.sectionC.platformTimeLabel.text = [NSString stringWithFormat:@"【平台复审时间】%@",[LGToolMethods stringFromInterval:self.investDetailModel.review_time_local.doubleValue withFormate:@"yyyy-MM-dd HH:mm:ss"]];
        }else{
            self.sectionC.platformTimeLabel.text = [NSString stringWithFormat:@"【平台复审时间】%@",@"暂无"];
        };
        
        if ([self.investDetailModel.operation intValue]== 6) {
            
            self.sectionC.timeWarnImageView.hidden = YES;
            self.sectionC.surplusTimeLabel.hidden = YES;
            self.sectionC.timeLabel.hidden = YES;
            
            NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:[self.investDetailModel.surplus_time doubleValue]];//目标时间
            
            self.sectionC.reviewLabel.text =[NSString stringWithFormat:@"【银行复审时间】%@",[LGToolMethods transformFormateDate:[LGToolMethods stringFromDate:fireDate] withFormat:@"yyyy-MM-dd HH:mm:ss"]];
            
            self.sectionC.timeWarnImageView.hidden = YES;
            self.sectionC.surplusTimeLabel.hidden = YES;
            self.sectionC.timeLabel.hidden = YES;
            
            
        }else{

            NSDate *today = [NSDate date];//当前时间
            
            
           // NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:[self.investDetailModel.surplus_time doubleValue]];//目标时间
            
            
            if ([self.investDetailModel.surplus_time doubleValue]<[today timeIntervalSince1970]) {
                self.sectionC.timeWarnImageView.hidden = YES;
                self.sectionC.surplusTimeLabel.hidden = YES;
                self.sectionC.timeLabel.hidden = YES;
                self.sectionC.reviewLabel.text = @"此标已经过期";
                _investmentStateButton.backgroundColor = UIColorFromRGB(0xb5b5b5);
                _investmentStateButton.userInteractionEnabled = NO;

            }else{
                
                [self timerFire];

            }
            
            
        }
        
        
    } withFailedBlock:^(NSError *error) {
        
        
    }withIndicator:NO  atView:self.view];
    
    
}
//时间倒计时
-(void)timerFire;
{

    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:[self.investDetailModel.surplus_time doubleValue]];//目标时间
    
    NSDate *today = [NSDate date];//当前时间
    unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *d = [calendar components:unitFlags fromDate:today toDate:fireDate options:0];
    
    self.sectionC.timeLabel.text =[NSString stringWithFormat:@"%ld天%ld小时%ld分%ld秒", (long)[d day], (long)[d hour], (long)[d minute], (long)[d second]];
    [self performSelector:@selector(timerFire) withObject:nil afterDelay:1];
    
    
    
}

- (void)creatInvestDetailView{
    
    _backGroundScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH , SCREEN_HEIGHT)];
    _backGroundScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT*2);
    _backGroundScrollView.delegate = self;
    _backGroundScrollView.backgroundColor = UIColorFromRGB(0xfafafa);
    [self.view addSubview:_backGroundScrollView];
    
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = [UIFont systemFontOfSize:17];
    _titleLabel.numberOfLines = 2;
    _titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [self.view addSubview:_titleLabel];
    
    CGSize maxSize = CGSizeMake(SCREEN_WIDTH-30,NSIntegerMax);
    
    CGSize titleSize = [self.investModel.title boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:_titleLabel.font} context:nil].size;
    _titleLabel.frame =CGRectMake(15,10, SCREEN_WIDTH-30, titleSize.height);
    _titleLabel.text =self.investModel.title;
    //    _titleLabel.textColor = UIColorFromRGB(0xffffff);
    [_backGroundScrollView addSubview: _titleLabel];
    
    if ([self.investDetailModel.borrow_type containsObject:@4]) {
        
        _titleLabel.textColor=UIColorFromString(@"#ff0000");
        
    }else{
        
        _titleLabel.textColor=[UIColor blackColor];
    }
    
    //   第一个模块
    self.sectionA = [[YPInvestDetailSectionOneView alloc]initWithFrame:CGRectMake(0, titleSize.height+10+10, SCREEN_WIDTH, 180)];
    self.sectionA.backgroundColor = [UIColor whiteColor];
    [_backGroundScrollView addSubview:self.sectionA];
    //    第二个模块
    self.sectionB = [[YPInvestDetailSectionTwoView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.sectionA.frame), SCREEN_WIDTH, 40)];
    self.sectionB.backgroundColor = [UIColor whiteColor];
    [_backGroundScrollView addSubview:self.sectionB];
    
    self.sectionC = [[YPInvestDetailSectionThreeView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.sectionB.frame), SCREEN_WIDTH, 50)];
    [_backGroundScrollView addSubview:_sectionC];
    
    
    NSMutableArray * optionArray = self.investDetailModel.option;;
    
    [optionArray enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
        OptionModel * model = [[OptionModel alloc]initWithDictionary:obj];
        [_optionArray addObject:model];
    }];
    
    if (_optionArray.count>0) {
        
        NSArray *arr = @[@"项目详情",@"风控审核",@"安全保障",@"投资记录"];
        for (NSInteger i = 0; i < arr.count; i ++) {
            //            YRChildVC *childVC = [[YRChildVC alloc] init];
            //        childVC.type = i == 0 ? YRTradingInvest : i == 1 ? YRTradingOrder : YRCapitalBuffers;
            //            childVC.type = i == 0 ? YRTradingInvest : i == 1 ? YRTradingOrder :i == 2 ? YRCapitalBuffers:YRDeposits;
            //            childVC.pictureArray =_optionArray;
            
            YRChildVC *childVC = [[YRChildVC alloc] initWithArr:_optionArray type:i == 0 ? YRTradingInvest : i == 1 ? YRTradingOrder :i == 2 ? YRCapitalBuffers:YRDeposits dic:_dataDic];
            
            
            childVC.title = arr[i];
            //            childVC.dataDic =_dataDic;
            [vcArr addObject:childVC];
        }
        
        controlVC = [[YRControlViewController alloc] init];
        controlVC.view.frame = CGRectMake(0, CGRectGetMaxY(self.sectionC.frame), SCREEN_WIDTH, SCREEN_HEIGHT - 64);
        controlVC.currentScrollIndex = 0;
        controlVC.viewControllersArray = vcArr;
        [self addChildViewController:controlVC];
        [_backGroundScrollView addSubview:controlVC.view];
        
    }
    
    
    UIView * bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-64-45, SCREEN_WIDTH, 45)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    
    //    计算器
    UIButton * calculatorButton = [UIButton buttonWithType:UIButtonTypeCustom];
    calculatorButton.frame = CGRectMake(0, 0, 45, 45);
    
    
    [calculatorButton addTarget:self action:@selector(calculatorButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    [calculatorButton setBackgroundImage:[UIImage imageNamed:@"calculator"] forState:UIControlStateNormal];
    [bottomView addSubview:calculatorButton];
    
    _investmentStateButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    _investmentStateButton.frame = CGRectMake(CGRectGetMaxX(calculatorButton.frame)+10,calculatorButton.top, SCREEN_WIDTH-calculatorButton.right - 10, calculatorButton.height);
    
    _investmentStateButton.backgroundColor = kColor_AppNavColor;
    
    [_investmentStateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [_investmentStateButton addTarget:self action:@selector(investmentStateButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    [bottomView addSubview:_investmentStateButton];
    
    [self configInvestStateBtn];
    
}

- (void)backTop{
    
    [_backGroundScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    _backGroundScrollView.scrollEnabled = YES;
    
    
    for (YRChildVC * childVC in vcArr) {
        childVC.web.scrollView.scrollEnabled = NO;
        childVC.auditScrollView.scrollEnabled = NO;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
